#pragma once
#include "ZuiLib.h"
#include "LRefObject.h"

namespace ZuiLib
{

class ZDrawControl :public ZControl
{
public:
	ZUI_CLASS_NAME("zui.DrawControl");

	ZDrawControl()
	{

	}

	virtual void DoPaint(ZRenderer* render, const RECT& rcPaint) 
	{
		ZControl::DoPaint(render, rcPaint);
		LuaState* L = ZScriptEngine::Instance()->GetLuaState();
		if(L)
			callLuaVirtualFunction(L, this, "doPaint",
			LuaClass<ZRenderer>::cToLua(L,render),
			toLua(L,rcPaint));
	}

	virtual void DoPostPaint(ZRenderer* render, const RECT& rcPaint)
	{
		ZControl::DoPostPaint(render, rcPaint);
		LuaState* L = ZScriptEngine::Instance()->GetLuaState();
		if(L)
			callLuaVirtualFunction(L, this, "doPostPaint",
			LuaClass<ZRenderer>::cToLua(L, render),
			toLua(L, rcPaint));
	}

	virtual void DoInit() 
	{
		ZControl::DoInit();
		LuaState* L = ZScriptEngine::Instance()->GetLuaState();
		if(L)
			callLuaVirtualFunction(L, this, "doInit");
	}

	virtual void DoDeinit() 
	{
		ZControl::DoDeinit();
		LuaState* L = ZScriptEngine::Instance()->GetLuaState();
		if(L)
			callLuaVirtualFunction(L, this, "doDeinit");
	}

	virtual void DoEvent(TEventUI& event)
	{
		ZControl::DoEvent(event);
		LuaState* L = ZScriptEngine::Instance()->GetLuaState();
		if(L)
			callLuaVirtualFunction(L, this, "doEvent");
	}
	virtual SIZE EstimateSize(SIZE szAvailable)
	{
		LuaState* L = ZScriptEngine::Instance()->GetLuaState();
		if (L)
		{
			LuaObject lsize = callLuaVirtualFunction(L, this, "estimateSize",toLua(L,szAvailable));
			if (lsize.isTable())
			{
				return toSize(lsize);
			}
		}
		return ZControl::EstimateSize(szAvailable);
	}
private:

};


class LDrawControl :public LRefObject<ZDrawControl>
{
public:

	BEGIN_MAP_FUNC(LDrawControl)
	END_MAP_FUNC
};


}//namespace
